*This script replicates Appendix Figure 5 in "The Coevolution of Networks of Interstate Support, Interstate Threat and Civil War" 

clear

*cd "[Directory Information Here]" 
cd "/Users/kcb38/Library/CloudStorage/Box-Box/Relation creation/JOPreplication/"

insheet using "relation_nodal.csv", clear
rename ccode1 ccode
sort ccode year 
save relation_nodal_merge, replace
insheet using "relation_network.csv", clear


*Merge in nodal characteristics of state 2
rename ccode2 ccode
sort ccode year
merge m:1 ccode year using relation_nodal_merge, nogen keep(match master)
rename ccode ccode2

*Narrow in on cases that received Soviet Support in 1988 and that were threat targets of the US
gen USSRsupport88=1 if ccode1==365 & year==1988 & support_bin==1
gen USAsupport88=1 if ccode1==2 & year==1988 & support_bin==1
sort ccode2 year
by ccode2: egen USSRsupport2=max(USSRsupport88)
by ccode2: egen USAsupport2=max(USAsupport88)
sort ccode1 ccode2 year
gen USAtarget2=1 if USSRsupport2==1 & threat_bin==1 & ccode1==2
list ccode2 if ccode1==2 & USAtarget2==1 & year==1988
*Cuba, Nicaragua, Angola, Libya, Iraq, Afghanistan, North Korea, Cambodia
list ccode2 if ccode1==2 & USAtarget2==1 & year==1992
* Cuba, Serbia, Angola, Iraq, Afghanistan, North Korea, Myanmar, Cambodia
list ccode2 if ccode1==2 & USAtarget2==1 & year==2008
* Cuba, North Korea, Myanmar


keep if USSRsupport2==1
gen intra_intens_bin=intra_intens
replace intra_intens_bin=1 if intra_intens_bin==2
gen civwar=0
replace civwar=1 if intra_intens==2
collapse (max) threat_bin intra_intens_bin civwar support_mi USAtarget2, by(ccode2 year)
collapse (sum) threat_bin intra_intens_bin civwar USAtarget2 (mean) support_mi, by(year)

twoway (line civwar year, sort lcolor(lavender) lwidth(thick) lpattern(dash)) (line USAtarget2 year, sort lcolor(teal) lwidth(thick) lpattern(shortdash)) (bar support_mi year, sort yaxis(2) fcolor(%40)), ytitle(# of USA threats/civil wars) yscale(range(0 10)) ytitle(Avg. Support Military Spending, axis(2)) legend(order(1 "Civil war" 2 "USA targets" 3 "Avg. Support Military Spending")) scheme(s1color)
graph save Figures/sovietcollapse, replace
graph export Figures/sovietcollapse.pdf, replace
